<include file="Common:header"/>
<style>
	.getbtn{
		background-color:#69d0fe ;
		color:#fff;
		border-radius: 5px;
		line-height: 30px;
		padding:0 7%;
	}
	.label_font{
		text-align: right;
	}
</style>
<body class="reset_password">
	<div class="header">
		重置密码
		<a href="javascript:history.back();" class="back">
			<img src="__PUBLIC__/img/back.png"><span class="back_cs">返回</span>
		</a>
	</div>
	<div class="form_content">
		<div class="form-input">
			<div class="user_name">
				<label for="mobile" class="label_font">手机号码：</label>
				<input class="input_e_i" type="tel" pattern="\d*" name="mobile" placeholder="填写11位手机号" value="<{$user_mobile}>">
			</div>
		</div>
		<div class="form-input">
			<div class="user_name">
				<label for="password" class="label_font">新密码：</label>
				<input class="input_e_i" type="password" name="password" placeholder="6-16位英文和数字" >
			</div>
		</div>
		<div class="form-input">
			<div class="user_name">
				<label for="captcha" class="label_font">验证码：</label>
				<input class="input_e_i" type="text" name="captcha" placeholder="短信验证码" style="width:41%;">
				<div style="float:right;width:35%;line-height:35px;">
				<button type="button" id="getCaptcha" class="getbtn" onclick="get_reset_captcha(this)">获取短信验证码</button>
				</div>
				
			</div>
		</div>
		<div class="max_box">
			<div class="form-input"> 
				<button type="button" value="" class="input_e_s" onclick="reset_password(this)">提&nbsp;交&nbsp;修&nbsp;改</button>
			</div>
		</div>
	</div>
	<empty name="none_menu">
		<include file="Common:menu"/>
	</empty>
</body>
</html>

<script type="text/javascript">
	function get_reset_captcha(obj){
		var mobile = $('input[name="mobile"]').val();
		if($(obj).attr('readonly')){
			return false;
		}
		if (!(/^1[3|4|5|8][0-9]\d{8}$/.test($.trim(mobile))))
		{
			layer.open({
				content: '手机号码格式错误',
			})
			return false;
		}
		$.ajax({
			type: "POST",
			url: "<{:U('Home/Login/sendResetCaptcha')}>",
			data: "mobile="+mobile+"",
			success: function(msg){
				if(msg.status == '-1'){
					layer.open({
						content: msg.msg,
					})
					$(obj).removeAttr('readonly');
				}
				else
				{
					layer.open({
						content: msg.msg,
					})
					getCaptchaSuccess();
				}
			}
		});
	}

	// 重新获取手机验证码
	function getCaptchaSuccess()
	{
		var duration = 59;	// 倒计时长 秒
		var obj = $('#getCaptcha');
		obj.attr('readonly', 'readonly');
		obj.addClass('readonlyBtn');
		obj.html('重新发送 ('+duration+' s)');
		var timing = self.setInterval(function(){
			if (duration > 0)
			{
				duration = duration - 1;
				obj.html('重新发送 ('+duration+' s)');
			}
			else
			{
				obj.html('重新获取验证码');
				obj.removeAttr('readonly');
				obj.removeClass('readonlyBtn');
				//清除循环定时器
				window.clearInterval(timing);
			}

		},1000);
	}

	function reset_password(obj){
		var mobile = $('input[name="mobile"]').val();
		var password = $('input[name="password"]').val();
		var captcha = $('input[name="captcha"]').val();

		$.ajax({
			type: "POST",
			url: "<{:U('Home/Login/reset_password')}>",
			data: "mobile="+mobile+"&password="+password+"&captcha="+captcha+"",
			success: function(msg){
				if(msg.status == '1'){
					layer.open({
						content: msg.msg,
						success:function(){
							window.location.href = '__SELF__';
						}
					})
					
				}else{
					layer.open({
						content: msg.msg,
					})
					return false;
				}
			}
		});
	}
</script>